//
//  AY_ReadManager.m
//  AiYue
//
//  Created by mac on 2023/10/18.
//

#import "AY_ReadManager.h"
#import "RDModelAgent.h"
#import "AY_ReadBookModel.h"

@interface AY_ReadManager()
@property (nonatomic,assign) SXThemeType tempTheme;
@end

@implementation AY_ReadManager
+ (AY_ReadManager *)sharedInstance {
    static AY_ReadManager *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (!sharedInstance) {
            sharedInstance.isYeJian = NO;
            sharedInstance = [[AY_ReadManager alloc] init];
            sharedInstance.fontSize = [AYMMKV getInt32ForKey:ReadFont defaultValue:23];
            sharedInstance.lineSpace = [AYMMKV getInt32ForKey:ReadLineSpace defaultValue:8];
            sharedInstance.brightness = kConfigMaxBrightnessValue;
            sharedInstance.fontColor = COLOR([AYMMKV getStringForKey:ReadTitleColor defaultValue:@"422D10"]);
            sharedInstance.theme = SXYellowTheme;
            sharedInstance.pageType = SXRealTypePage;
            sharedInstance.isNight = NO;
            sharedInstance.firstLineHeadIndent = 0;
            sharedInstance.topColor = [UIColor whiteColor];
            sharedInstance.isHuYan = NO;
            sharedInstance.huYanAlpha = 0;
        }
    });
    return sharedInstance;
}

-(CGFloat)chapterFontSize
{
    return [AYMMKV getInt32ForKey:ReadFont defaultValue:23];
}

- (CGFloat)lineSpace {
    return [AYMMKV getInt32ForKey:ReadLineSpace defaultValue:8];
}

-(CGFloat)chapterLineSpace
{
    return [AYMMKV getInt32ForKey:ReadLineSpace defaultValue:8]+6;
}

- (void)setIsHuYan:(BOOL)isHuYan
{
    _isHuYan = isHuYan;
    if (isHuYan == YES) {
        self.huYanAlpha = 0.2;
    }else{
        self.huYanAlpha = 0;
    }
}

+ (NSMutableArray *)getThemes {
    NSMutableArray *arr = [NSMutableArray array];
    NSArray *datas = @[@{
        @"readBackColor": @"F8F8F8",
        @"readToolColor": @"FFFFFF",
        @"readTitleColor": @"333333",
        @"readLineColor": @"ECECEC",
    },@{
        @"readBackColor": @"F6EFDC",
        @"readToolColor": @"FEF6E9",
        @"readTitleColor": @"422D10",
        @"readLineColor": @"EDE5D8",
    },@{
        @"readBackColor": @"CFE0CD",
        @"readToolColor": @"DEEADE",
        @"readTitleColor": @"2E442F",
        @"readLineColor": @"CFDBD1",
    },@{
        @"readBackColor": @"C6D6EF",
        @"readToolColor": @"D7E4F5",
        @"readTitleColor": @"31415A",
        @"readLineColor": @"C9D6E7",
    },@{
        @"readBackColor": @"161616",
        @"readToolColor": @"212224",
        @"readTitleColor": @"999999",
        @"readLineColor": @"6F6F6F",
    },];
    for (int i = 0; i < datas.count; i++) {
        AY_ReadBookModel *bookModel = [[AY_ReadBookModel alloc] initWithDictionary:datas[i] error:nil];
        [arr addObject:bookModel];
    }
    return arr;
}
@end
